package com.zj.leetcode.medium.binarySearch;

/**
 * @program: algorithm
 * @description: 有序数组中的单一元素
 * 540 single-element-in-a-sorted-array
 * @author: Zhang Bo
 * @create: 2022-04-21 18:56:05
 **/
public class SingleElementInASortedArray {
    public static void main(String[] args) {
        Solution solution = new SingleElementInASortedArray().new Solution();
    }

    //leetcode submit region begin(Prohibit modification and deletion)
    class Solution {
        public int singleNonDuplicate(int[] nums) {

            for (int i = 0; i < nums.length - 1; i += 2) {
                if(nums[i] != nums[i + 1]){
                    return nums[i];
                }
            }

            return nums[nums.length - 1];
        }


        public int singleNonDuplicate01(int[] nums) {

            int l = 0;
            int r = nums.length - 1;
            while (l < r){
                l++;

            }

            return nums[nums.length - 1];
        }
    }
//leetcode submit region end(Prohibit modification and deletion)

}
